package cn.stylefeng.guns.core.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 实体验证aop
 *
 * @Auther dusd
 * @Date 2019/4/28 19:46
 * @Copyright 版权由上海卓繁信息技术股份有限公司拥有
 */
@Aspect
@Component
@Order(105 )
public class ValidatedAop {

    @Pointcut("execution(public  * cn.stylefeng..modular..controller..*.*(..))")
    private void aspect(){}//定义一个切入点

//    @Before("aspect()")
//    public void before(JoinPoint joinPoint) {
//        System.out.println("[Aspect1] before advise");
//    }

    @Around("aspect()")
    public Object  doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] objs = joinPoint.getArgs();
//        for (int i = 0; i < objs.length; i++) {
//            if(objs[i] instanceof BindingResult) {
//                BindingResult bindingResult = (BindingResult)objs[i];
//                if (bindingResult.hasErrors()) {
//                    StringBuilder errorMsg = new StringBuilder("<br/>");
//                    for (ObjectError error : bindingResult.getAllErrors()) {
//                        errorMsg.append(error.getDefaultMessage()).append("<br/>");
//                    }
//                    errorMsg.delete(errorMsg.length() - 1, errorMsg.length());
//                    throw new RequestEmptyException(errorMsg.toString());
//                    //return new ErrorResponseData(500,errorMsg.toString());
//                }
//            }
//        }
        return joinPoint.proceed(objs);
    }
}
